{"ast":null,"code":"import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport usePatchElement from '../../_util/hooks/usePatchElement';\nimport { withConfirm, withError, withInfo, withSuccess, withWarn } from '../confirm';\nimport HookModal from './HookModal';\nlet uuid = 0;\nconst ElementsHolder = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((_props, ref) => {\n  const [elements, patchElement] = usePatchElement();\n  React.useImperativeHandle(ref, () => ({\n    patchElement\n  }), []);\n  // eslint-disable-next-line react/jsx-no-useless-fragment\n  return /*#__PURE__*/React.createElement(React.Fragment, null, elements);\n}));\nfunction useModal() {\n  const holderRef = React.useRef(null);\n  // ========================== Effect ==========================\n  const [actionQueue, setActionQueue] = React.useState([]);\n  React.useEffect(() => {\n    if (actionQueue.length) {\n      const cloneQueue = _toConsumableArray(actionQueue);\n      cloneQueue.forEach(action => {\n        action();\n      });\n      setActionQueue([]);\n    }\n  }, [actionQueue]);\n  // =========================== Hook ===========================\n  const getConfirmFunc = React.useCallback(withFunc => function hookConfirm(config) {\n    var _a;\n    uuid += 1;\n    const modalRef = /*#__PURE__*/React.createRef();\n    let closeFunc;\n    const modal = /*#__PURE__*/React.createElement(HookModal, {\n      key: `modal-${uuid}`,\n      config: withFunc(config),\n      ref: modalRef,\n      afterClose: () => {\n        closeFunc === null || closeFunc === void 0 ? void 0 : closeFunc();\n      }\n    });\n    closeFunc = (_a = holderRef.current) === null || _a === void 0 ? void 0 : _a.patchElement(modal);\n    return {\n      destroy: () => {\n        function destroyAction() {\n          var _a;\n          (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.destroy();\n        }\n        if (modalRef.current) {\n          destroyAction();\n        } else {\n          setActionQueue(prev => [].concat(_toConsumableArray(prev), [destroyAction]));\n        }\n      },\n      update: newConfig => {\n        function updateAction() {\n          var _a;\n          (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.update(newConfig);\n        }\n        if (modalRef.current) {\n          updateAction();\n        } else {\n          setActionQueue(prev => [].concat(_toConsumableArray(prev), [updateAction]));\n        }\n      }\n    };\n  }, []);\n  const fns = React.useMemo(() => ({\n    info: getConfirmFunc(withInfo),\n    success: getConfirmFunc(withSuccess),\n    error: getConfirmFunc(withError),\n    warning: getConfirmFunc(withWarn),\n    confirm: getConfirmFunc(withConfirm)\n  }), []);\n  return [fns, /*#__PURE__*/React.createElement(ElementsHolder, {\n    key: \"modal-holder\",\n    ref: holderRef\n  })];\n}\nexport default useModal;","map":{"version":3,"names":["_toConsumableArray","React","usePatchElement","withConfirm","withError","withInfo","withSuccess","withWarn","HookModal","uuid","ElementsHolder","memo","forwardRef","_props","ref","elements","patchElement","useImperativeHandle","createElement","Fragment","useModal","holderRef","useRef","actionQueue","setActionQueue","useState","useEffect","length","cloneQueue","forEach","action","getConfirmFunc","useCallback","withFunc","hookConfirm","config","_a","modalRef","createRef","closeFunc","modal","key","afterClose","current","destroy","destroyAction","prev","concat","update","newConfig","updateAction","fns","useMemo","info","success","error","warning","confirm"],"sources":["/data/messenger.client/node_modules/antd/es/modal/useModal/index.js"],"sourcesContent":["import _toConsumableArray from \"@babel/runtime/helpers/esm/toConsumableArray\";\nimport * as React from 'react';\nimport usePatchElement from '../../_util/hooks/usePatchElement';\nimport { withConfirm, withError, withInfo, withSuccess, withWarn } from '../confirm';\nimport HookModal from './HookModal';\nlet uuid = 0;\nconst ElementsHolder = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef((_props, ref) => {\n  const [elements, patchElement] = usePatchElement();\n  React.useImperativeHandle(ref, () => ({\n    patchElement\n  }), []);\n  // eslint-disable-next-line react/jsx-no-useless-fragment\n  return /*#__PURE__*/React.createElement(React.Fragment, null, elements);\n}));\nfunction useModal() {\n  const holderRef = React.useRef(null);\n  // ========================== Effect ==========================\n  const [actionQueue, setActionQueue] = React.useState([]);\n  React.useEffect(() => {\n    if (actionQueue.length) {\n      const cloneQueue = _toConsumableArray(actionQueue);\n      cloneQueue.forEach(action => {\n        action();\n      });\n      setActionQueue([]);\n    }\n  }, [actionQueue]);\n  // =========================== Hook ===========================\n  const getConfirmFunc = React.useCallback(withFunc => function hookConfirm(config) {\n    var _a;\n    uuid += 1;\n    const modalRef = /*#__PURE__*/React.createRef();\n    let closeFunc;\n    const modal = /*#__PURE__*/React.createElement(HookModal, {\n      key: `modal-${uuid}`,\n      config: withFunc(config),\n      ref: modalRef,\n      afterClose: () => {\n        closeFunc === null || closeFunc === void 0 ? void 0 : closeFunc();\n      }\n    });\n    closeFunc = (_a = holderRef.current) === null || _a === void 0 ? void 0 : _a.patchElement(modal);\n    return {\n      destroy: () => {\n        function destroyAction() {\n          var _a;\n          (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.destroy();\n        }\n        if (modalRef.current) {\n          destroyAction();\n        } else {\n          setActionQueue(prev => [].concat(_toConsumableArray(prev), [destroyAction]));\n        }\n      },\n      update: newConfig => {\n        function updateAction() {\n          var _a;\n          (_a = modalRef.current) === null || _a === void 0 ? void 0 : _a.update(newConfig);\n        }\n        if (modalRef.current) {\n          updateAction();\n        } else {\n          setActionQueue(prev => [].concat(_toConsumableArray(prev), [updateAction]));\n        }\n      }\n    };\n  }, []);\n  const fns = React.useMemo(() => ({\n    info: getConfirmFunc(withInfo),\n    success: getConfirmFunc(withSuccess),\n    error: getConfirmFunc(withError),\n    warning: getConfirmFunc(withWarn),\n    confirm: getConfirmFunc(withConfirm)\n  }), []);\n  return [fns, /*#__PURE__*/React.createElement(ElementsHolder, {\n    key: \"modal-holder\",\n    ref: holderRef\n  })];\n}\nexport default useModal;"],"mappings":"AAAA,OAAOA,kBAAkB,MAAM,8CAA8C;AAC7E,OAAO,KAAKC,KAAK,MAAM,OAAO;AAC9B,OAAOC,eAAe,MAAM,mCAAmC;AAC/D,SAASC,WAAW,EAAEC,SAAS,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,QAAQ,QAAQ,YAAY;AACpF,OAAOC,SAAS,MAAM,aAAa;AACnC,IAAIC,IAAI,GAAG,CA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